/*
 * @Author: EyeSklear 1814580085@qq.com
 * @Date: 2024-01-24 10:24:51
 * @LastEditors: EyeSklear 1814580085@qq.com
 * @LastEditTime: 2024-01-24 10:25:21
 * @FilePath: \Scene_Back\src\common\guards\auth.guard.ts
 * @Description:
 *
 * Copyright (c) 2024 by EyeSklear , All Rights Reserved.
 */
import { ExecutionContext, Injectable } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {
  constructor(private reflector: Reflector) {
    super();
  }

  canActivate(context: ExecutionContext) {
    const isPublic = this.reflector.getAllAndOverride('isPublic', [
      context.getHandler(),
      context.getClass(),
    ]);

    if (isPublic) return true;

    return super.canActivate(context);
  }
}
